home *** CD-ROM | disk | FTP | other *** search
/ Clickx 23 / Clickx 23.iso / DATA / wordpress / wp-admin / categories.php < prev    next >
Encoding:
PHP Script  |  2005-08-14  |  6.3 KB  |  187 lines

  1. <?php
  2. require_once('admin.php');
  3.  
  4. $title = __('Categories');
  5. $parent_file = 'edit.php';
  6.  
  7. $wpvarstoreset = array('action','cat');
  8. for ($i=0; $i<count($wpvarstoreset); $i += 1) {
  9.     $wpvar = $wpvarstoreset[$i];
  10.     if (!isset($$wpvar)) {
  11.         if (empty($_POST["$wpvar"])) {
  12.             if (empty($_GET["$wpvar"])) {
  13.                 $$wpvar = '';
  14.             } else {
  15.                 $$wpvar = $_GET["$wpvar"];
  16.             }
  17.         } else {
  18.             $$wpvar = $_POST["$wpvar"];
  19.         }
  20.     }
  21. }
  22.  
  23. switch($action) {
  24.  
  25. case 'addcat':
  26.     if ($user_level < 3)
  27.         die (__('Cheatin’ uh?'));
  28.     
  29.     $cat_name= wp_specialchars($_POST['cat_name']);
  30.     $id_result = $wpdb->get_row("SHOW TABLE STATUS LIKE '$wpdb->categories'");
  31.     $cat_ID = $id_result->Auto_increment;
  32.     $category_nicename = sanitize_title($cat_name, $cat_ID);
  33.     $category_description = $_POST['category_description'];
  34.     $cat = intval($_POST['cat']);
  35.     
  36.     $wpdb->query("INSERT INTO $wpdb->categories (cat_ID, cat_name, category_nicename, category_description, category_parent) VALUES ('0', '$cat_name', '$category_nicename', '$category_description', '$cat')");
  37.     do_action('add_category', $wpdb->insert_id);
  38.     
  39.     header('Location: categories.php?message=1#addcat');
  40. break;
  41.  
  42. case 'delete':
  43.  
  44.     check_admin_referer();
  45.  
  46.     $cat_ID = (int) $_GET['cat_ID'];
  47.     $cat_name = get_catname($cat_ID);
  48.     $category = $wpdb->get_row("SELECT * FROM $wpdb->categories WHERE cat_ID = '$cat_ID'");
  49.     $cat_parent = $category->category_parent;
  50.  
  51.     if ( 1 == $cat_ID )
  52.         die(sprintf(__("Can't delete the <strong>%s</strong> category: this is the default one"), $cat_name));
  53.  
  54.     if ( $user_level < 3 )
  55.         die (__('Cheatin’ uh?'));
  56.  
  57.     $wpdb->query("DELETE FROM $wpdb->categories WHERE cat_ID = '$cat_ID'");
  58.     $wpdb->query("UPDATE $wpdb->categories SET category_parent = '$cat_parent' WHERE category_parent = '$cat_ID'");
  59.     // TODO: Only set categories to general if they're not in another category already
  60.     $wpdb->query("UPDATE $wpdb->post2cat SET category_id='1' WHERE category_id='$cat_ID'");
  61.     do_action('delete_category', $cat_ID);
  62.  
  63.     header('Location: categories.php?message=2');
  64.  
  65. break;
  66.  
  67. case 'edit':
  68.  
  69.     require_once ('admin-header.php');
  70.     $cat_ID = (int) $_GET['cat_ID'];
  71.     $category = $wpdb->get_row("SELECT * FROM $wpdb->categories WHERE cat_ID = '$cat_ID'");
  72.     $cat_name = $category->cat_name;
  73.     ?>
  74.  
  75. <div class="wrap">
  76.  <h2><?php _e('Edit Category') ?></h2>
  77.  <form name="editcat" action="categories.php" method="post">
  78.       <table class="editform" width="100%" cellspacing="2" cellpadding="5">
  79.         <tr>
  80.           <th width="33%" scope="row"><?php _e('Category name:') ?></th>
  81.           <td width="67%"><input name="cat_name" type="text" value="<?php echo wp_specialchars($cat_name); ?>" size="40" /> <input type="hidden" name="action" value="editedcat" />
  82. <input type="hidden" name="cat_ID" value="<?php echo $cat_ID ?>" /></td>
  83.         </tr>
  84.         <tr>
  85.             <th scope="row"><?php _e('Category slug:') ?></th>
  86.             <td><input name="category_nicename" type="text" value="<?php echo wp_specialchars($category->category_nicename); ?>" size="40" /></td>
  87.         </tr>
  88.         <tr>
  89.             <th scope="row"><?php _e('Category parent:') ?></th>
  90.             <td>        
  91.             <select name='cat'>
  92.       <option value='0' <?php if (!$category->category_parent) echo " selected='selected'"; ?>><?php _e('None') ?></option>
  93.       <?php wp_dropdown_cats($category->cat_ID, $category->category_parent); ?>
  94.       </select></td>
  95.         </tr>
  96.         <tr>
  97.             <th scope="row"><?php _e('Description:') ?></th>
  98.             <td><textarea name="category_description" rows="5" cols="50" style="width: 97%;"><?php echo wp_specialchars($category->category_description, 1); ?></textarea></td>
  99.         </tr>
  100.         </table>
  101.       <p class="submit"><input type="submit" name="submit" value="<?php _e('Edit category') ?> »" /></p>
  102.  </form>
  103.  <p><a href="categories.php"><?php _e('« Return to category list'); ?></a></p>
  104. </div>
  105.     <?php
  106.  
  107. break;
  108.  
  109. case 'editedcat':
  110.     if ($user_level < 3)
  111.         die (__('Cheatin’ uh?'));
  112.     
  113.     $cat_name = wp_specialchars($_POST['cat_name']);
  114.     $cat_ID = (int) $_POST['cat_ID'];
  115.     $category_nicename = sanitize_title($_POST['category_nicename'], $cat_ID);
  116.     $category_description = $_POST['category_description'];
  117.     
  118.     $wpdb->query("UPDATE $wpdb->categories SET cat_name = '$cat_name', category_nicename = '$category_nicename', category_description = '$category_description', category_parent = '$cat' WHERE cat_ID = '$cat_ID'");
  119.  
  120.     header('Location: categories.php?message=3');
  121. break;
  122.  
  123. default:
  124.  
  125. require_once ('admin-header.php');
  126.  
  127. $messages[1] = __('Category added.');
  128. $messages[2] = __('Category deleted.');
  129. $messages[3] = __('Category updated.');
  130. ?>
  131.  
  132. <?php if (isset($_GET['message'])) : ?>
  133. <div class="updated"><p><?php echo $messages[$_GET['message']]; ?></p></div>
  134. <?php endif; ?>
  135.  
  136. <div class="wrap">
  137. <?php if ( $user_level > 3 ) : ?>
  138.     <h2><?php printf(__('Categories (<a href="%s">add new</a>)'), '#addcat') ?> </h2>
  139. <?php else : ?>
  140.     <h2><?php _e('Categories') ?> </h2>
  141. <?php endif; ?>
  142. <table width="100%" cellpadding="3" cellspacing="3">
  143.     <tr>
  144.         <th scope="col"><?php _e('ID') ?></th>
  145.         <th scope="col"><?php _e('Name') ?></th>
  146.         <th scope="col"><?php _e('Description') ?></th>
  147.         <th scope="col"><?php _e('# Posts') ?></th>
  148.         <th colspan="2"><?php _e('Action') ?></th>
  149.     </tr>
  150. <?php
  151. cat_rows();
  152. ?>
  153. </table>
  154.  
  155. </div>
  156.  
  157. <?php if ( $user_level > 3 ) : ?>
  158. <div class="wrap">
  159.     <p><?php printf(__('<strong>Note:</strong><br />Deleting a category does not delete posts from that category, it will just set them back to the default category <strong>%s</strong>.'), get_catname(1)) ?>
  160.   </p>
  161. </div>
  162.  
  163. <div class="wrap">
  164.     <h2><?php _e('Add New Category') ?></h2>
  165.     <form name="addcat" id="addcat" action="categories.php" method="post">
  166.         
  167.         <p><?php _e('Name:') ?><br />
  168.         <input type="text" name="cat_name" value="" /></p>
  169.         <p><?php _e('Category parent:') ?><br />
  170.         <select name='cat' class='postform'>
  171.         <option value='0'><?php _e('None') ?></option>
  172.         <?php wp_dropdown_cats(0); ?>
  173.         </select></p>
  174.         <p><?php _e('Description: (optional)') ?> <br />
  175.         <textarea name="category_description" rows="5" cols="50" style="width: 97%;"></textarea></p>
  176.         <p class="submit"><input type="hidden" name="action" value="addcat" /><input type="submit" name="submit" value="<?php _e('Add Category »') ?>" /></p>
  177.     </form>
  178. </div>
  179. <?php endif; ?>
  180.  
  181. <?php
  182. break;
  183. }
  184.  
  185. include('admin-footer.php');
  186. ?>
  187.